
import { useState } from 'react'
import { useRequest } from 'alova/client'
import { Space, Input, Button } from 'antd'

import { Http } from '../../API'

const WijmoComCourier = ({ data, Off, ModalEvent }) => {
    const { orderMasterUuid } = data
    const [Status, setStatus] = useState('')
    const [loading, setLoading] = useState(false)
    const [LogisticNumber, setLogisticNumber] = useState()

    const { send } = useRequest(params => Http({ url: 'posBuyReturnInfoUpdateLogisticNumber', params }), { immediate: false })

    const onSubmit = () => {
        setLoading(true)
        if (!LogisticNumber) {
            setStatus('error')
            setLoading(false)
            return false
        }
        setStatus('')
        send({ uuid: orderMasterUuid, LogisticNumber }).then(() => {
            ModalEvent.emit({ type: 'Refresh' })
            Off()
        })
    }

    return (
        <div className="WijmoComCourier">
            <Space.Compact style={{ width: '100%' }}>
                <Input status={Status} placeholder='请输入快递单号' size='large' value={LogisticNumber} onChange={e => setLogisticNumber(e.target.value)} />
                <Button type="primary" size='large' onClick={onSubmit} loading={loading}>提交</Button>
            </Space.Compact>
        </div>
    );
};

export default WijmoComCourier;